package sms;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;

public class SMSDemo {
    public static void main(String[] args) {
        DefaultProfile profile =DefaultProfile.getProfile("cn-hangzhou",
                        "LTAI5tLwAgq46J5UzFvy8YKT",
                        "2NpPlyFDIIEIJij04h4yEI79nS9qzQ");
        
        IAcsClient client = new DefaultAcsClient(profile);
        SendSmsRequest request = new SendSmsRequest();
        //接收短信的手机号码
        request.setPhoneNumbers("17358837235");
        //短信签名名称
        request.setSignName("焦金喜的博客");
        //短信模板CODE
        request.setTemplateCode("SMS_461986294");
        //code阿里云模板只有一个短信参数
        request.putQueryParameter("TemplateParam","{'code':'1234'}");
        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println("发送短信响应信息："+new Gson().toJson(response));
            if(response.getCode().equals("OK")){
                System.out.println("发送成功");
            }else{
                System.out.println("发送失败");
            }
        } catch (ClientException e) {
           System.out.println("发送失败;失败原因："+e.getMessage());
        }
    }
}